﻿using AutoMapper;
using MediatR;
using SmartCity.ProcessEngine.API.Read.Application.Commands.FormTypes;
using SmartCity.ProcessEngine.API.Read.DTO;
using SmartCity.ProcessEngine.Domain;
using SmartCity.ProcessEngine.Errorcode;
using SmartCity.ProcessEngine.Infrastructure.Interfaces;

namespace SmartCity.ProcessEngine.API.Read.Application.CommandHandlers.FormTypes
{
    public class IndustryQueryCommandHandler:IRequestHandler<IndustryQueryCommand, ApiResult<List<IndustryDto>>>
    {
        private readonly IBaseRepository<Industry> industryRep;
        private readonly IMapper mapper;

        public IndustryQueryCommandHandler(IBaseRepository<Industry> industryRep,IMapper mapper)
        {
            this.industryRep = industryRep;
            this.mapper = mapper;
        }

        public Task<ApiResult<List<IndustryDto>>> Handle(IndustryQueryCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<IndustryDto>> result = new ApiResult<List<IndustryDto>>();
            result.code = ApiEnum.SearchSuccess;
            result.message = "成功";

            var list = industryRep.GetAll().ToList();
            result.data = mapper.Map<List<IndustryDto>>(list);

            return Task.FromResult(result);
        }
    }
}
